<template>
	<view class="template-index tn-safe-area-inset-bottom">

		<!-- 顶部自定义导航 -->
		<tn-nav-bar :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view class="custom-nav__back" @click="tn('/subpages/exam/search/search')">
					<view class="tn-icon-search-list"></view>
				</view>
				<view class="" style="width: 72vw;overflow: hidden;margin-top: 36rpx;">
					<tn-tabs :list="scrollList" :current="current" @change="tabChange" activeColor="#000" :bold="true"
						:fontSize="36"></tn-tabs>
				</view>
			</view>
		</tn-nav-bar>

		<!-- 轮播图开始-->
		<view class="tn-margin-top-sm" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<swiper class="card-swiper" :circular="true" :autoplay="true" duration="500" interval="8000" @change="cardSwiper">
				<swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''"
					@click="tn(item.navigate)">
					<view class="swiper-item image-banner">
						<image :src="item.url + item.path" mode="aspectFill" style="border-radius: 6px;"></image>
					</view>
					<view class="swiper-item-text">
						<view class="tn-text-bold tn-color-white" style="font-size: 50rpx;">{{item.first_title}}</view>
						<view class="tn-color-white tn-padding-top" style="font-size: 30rpx;">{{item.second_title}}</view>
						<view class="tn-text-sm tn-text-bold tn-color-white tn-padding-top-sm tn-padding-bottom-sm"></view>
					</view>
				</swiper-item>
			</swiper>
			<view class="indication">
				<block v-for="(item,index) in swiperList" :key="index">
					<view class="spot" :class="cardCur==index?'active':''"></view>
				</block>
			</view>
		</view>
		<!-- 轮播图结束 -->


		<!-- 通知开始-->
		<view class="tn-bg-white" style="border-radius: 20rpx;" v-if="noticeList.length > 0">
			<tn-notice-bar :list="noticeList" :duration="5000" mode="vertical" leftIconName="notice" @click="clickNotice"></tn-notice-bar>
		</view>
		<!-- 通知结束 -->

		<!-- 菜单 start-->
		<view class="tn-flex" style="flex-wrap:wrap;width: 100%;margin-top: 30rpx">
			<block v-for="(item, index) in menuList" :key="item.path">
				<view class="tn-radius" @click="tn(item.navigate)" style="width: 20%;margin-bottom: 0rpx;">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
							:style="'background-image:url('+ item.url + item.path +');background-size:100% 100%;background-size: cover;'">
						</view>
						<view class="tn-color-gray--dark tn-text-center tn-text-df">
							<text class="tn-text-ellipsis">{{ item.title }}</text>
						</view>
					</view>
				</view>
			</block>
		</view>
		<!-- 菜单 end-->

		<!-- 胶囊banner -->
		<!-- <view class="tn-flex tn-flex-wrap tn-padding-xs tn-margin-top" @click="tn('/homePages/member')">
      <view class="" style="width: 100%;">
        <view class="image-piccapsule tn-shadow-blur" style="background-image:url('https://cdn.nlark.com/yuque/0/2022/png/280373/1649746862795-assets/web-upload/f8e5a420-53d1-4c8c-b06f-35031672088c.png');">
           <view class="image-capsule">
           </view>
         </view>  
      </view>  
    </view> -->

		<!-- 标题-->
<!-- 		<view class="tn-flex tn-flex-row-between tn-flex-col-center" style="margin-top: 0rpx;">
			<view class="justify-content-item tn-margin tn-text-bold tn-text-xl blue-title">
				答题导航
			</view>
		</view> -->

		<!-- 功能入口-->
<!-- 		<view
			class="tn-info__container tn-flex tn-flex-wrap tn-flex-col-center tn-flex-row-between tn-margin-left tn-margin-right">
			<block v-for="(item, index) in tuniaoData" :key="index">
				<view
					class="tn-info__item tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between tn-color-white tn-shadow-blur"
					:style="'background-color:'+ item.color +';'" @click="tn(item.url)">
					<view class="tn-info__item__left tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-left">
						<view class="tn-info__item__left__content">
							<view class="tn-info__item__left__content--title tn-text-bold" style="font-size: 38rpx;">{{ item.title }}
							</view>
							<view class="tn-info__item__left__content--data tn-padding-top-xs">
								{{ item.value }}
								<text class="tn-icon-right tn-padding-left-xs"></text>
							</view>
						</view>
					</view>
					<view class="tn-info__item__right">
						<view class="tn-info__item__right--icon">
							<view :class="[`tn-icon-${item.icon}`]"></view>
						</view>
					</view>
					<view class="tn-info__item__bottom">
						<view class='name tn-text-sm tn-color-gray' style="margin-left: -10rpx;">
							<text class="tn-icon-code tn-padding-right-xs" style="opacity: 0;"></text>
						</view>
					</view>
				</view>
			</block>
		</view> -->
		<!-- 功能入口结束 -->

		<!-- 推荐试题开始-->
		<view class="tn-flex tn-flex-row-between tn-flex-col-center">
			<view class="justify-content-item tn-margin tn-text-bold tn-text-xl blue-title">
				推荐试题
			</view>
			<view class="justify-content-item tn-margin-right tn-text-df tn-color-gray">
				<text class="tn-padding-xs" @click="tn('/subpages/exam/search/search')">更多</text>
				<text class="tn-icon-right"></text>
			</view>
		</view>
		<view class="" style="padding-bottom: 60rpx;margin-top: -30rpx; position: relative;">
			<!-- 推荐试题普通列表开始 -->
			<view class="tn-padding-bottom-xl">
				<block v-for="(item, index) in recommendExamList" :key="index">
					<view class="home-shadow tn-margin" @click="tn('/subpages/exam/collection/detail?uid='+ item.uid)">
						<view class="tn-flex">
							<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
								<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
									<text class="">{{ item.title }}</text>
								</view>
								<view class="tn-padding-top-xs" style="min-height: 90rpx;">
									<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
										<!-- {{ item.remark }} -->
									</text>
								</view>
								<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-xs">
									<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
										<text class="tn-tag-content__item--prefix">#</text> {{ item.category.title }}
									</view>
									<view class="justify-content-item tn-color-gray tn-text-center tn-color-gray"
										style="padding-top: 5rpx;">
										<text class="tn-icon-write tn-padding-right-xs tn-text-lg tn-color-gray"></text>
										<text class="tn-padding-right tn-text-df">{{ item.submit }}</text>
										<text class="tn-icon-like-lack tn-padding-right-xs tn-text-lg tn-color-gray"></text>
										<text class="tn-text-df">{{ item.collect }}</text>
									</view>
								</view>
							</view>
							<view class="image-pic tn-margin-sm" :style="'background-image:url(' + item.url + item.path + ')'">
								<view class="image-article">
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<!-- 推荐试题普通列表结束 -->
			<!-- 推荐试题大图开始 -->
			<!-- <view class="">
				<block v-for="(item,index) in recommendExamList" :key="index">
					<block v-if="index % 6 == 0 && index != 0">
						<view class="article-shadow tn-margin-xs tn-padding-sm"
							@click="tn('/subpages/exam/collection/detail?uid='+ item.uid +'')">
							<view class="image-pic" :style="'background-image:url(' + item.url + item.path + ')'">
								<view class="image-design">
								</view>
							</view>
							<view class="tn-margin-top tn-padding-bottom-sm">
								<view class="tn-text-lg clamp-text-1 tn-text-justify">
									<text class="">{{ item.title }}</text>
								</view>
								<view class="tn-padding-top-xs" style="">
									<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify collection-remark">
										{{ item.remark }}
									</text>
								</view>
								<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
									<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
										<text class="tn-tag-content__item--prefix">#</text> {{ item.category.title }}
									</view>
									<view class="justify-content-item tn-color-gray tn-text-center" style="padding-top: 5rpx;">
										<text class="tn-icon-write tn-padding-right-xs tn-text-lg"></text>
										<text class="tn-padding-right tn-text-df">{{ item.submit }}</text>
										<text class="tn-icon-like-lack tn-padding-right-xs tn-text-lg"></text>
										<text class="tn-text-df">{{ item.collect }}</text>
									</view>
								</view>
							</view>
						</view>
					</block>
				</block>
			</view> -->
			<!-- 推荐试题大图结束 -->
			<tn-load-more :status="loadStatus"></tn-load-more>
		</view>
		<!-- 推荐试题结束 -->

		<view class='tn-tabbar-height'></view>

	</view>
</template>

<script>
	import {
		getHomeMenuList,
		getBannerList,
		getHomeNoticeList
	} from "@/utils/api/config.js"
	import {
		getCollectionList
	} from "@/utils/api/exam.js"
	export default {
		name: 'Home',
		data() {
			return {
				cardCur: 0,
				isAndroid: true,
				swiperList: [],
				scrollList: [{
					name: "兔兔答题"
				}], // 顶部选项卡
				menuList: [],
				loadStatus: 'nomore',
				recommendExamList: [],
				noticeList: [], // 组件公告内容
				noticeListArray: [], // 组件公告原生数据
				tuniaoData: [{
						title: '刷题指南',
						icon: 'image-text-fill',
						color: '#5177EE',
						value: '事半功倍',
						url: '/subpages/help/content?uid=482928805799789437'
					},
					{
						title: '热门试题',
						icon: 'calendar-fill',
						color: '#19cf8a',
						value: '查看详情',
						url: '/subpages/exam/search/search'
					},
					{
						title: '面试攻略',
						icon: 'image-fill',
						color: '#5F4FD9',
						value: '涨薪技巧',
						url: '/subpages/help/content?uid=482928747700290226'
					},
					{
						title: '兔兔答题',
						icon: 'theme-fill',
						color: '#954FF6',
						value: '了解兔兔',
						url: '/subpages/help/about/about'
					}
				],
				examSearchWhere: {
					page: 1,
					size: 20,
				},
				isFinish: false,
			}
		},
		created() {
			const systemInfo = uni.getSystemInfoSync()
			if (systemInfo.system.toLocaleLowerCase().includes('ios')) {
				this.isAndroid = false
			} else {
				this.isAndroid = true
			}
		},
		onLoad() {
			this.getMenuList()
			this.getBannerList()
			this.getRecommendExamList()
			this.getHomeNoticeList()
		},
		methods: {
			// 获取公告
			getHomeNoticeList() {
				getHomeNoticeList().then(res => {
					for (var i = 0; i < res.data.length; i++) {
						this.noticeList[i] = res.data[i].title
					}
					this.noticeListArray = res.data
				})
			},
			// 获取推荐试卷
			getRecommendExamList() {
				if (this.isFinish) {
					this.$func.showToast("暂无新试题")
					return
				}
				this.loadStatus = "loading"
				uni.showLoading({
					title: "试题努力加载中",
					icon: "none"
				})
				getCollectionList(this.examSearchWhere).then(res => {
					uni.hideLoading()
					if (res.code == 100) {
						this.recommendExamList.push(...res.data.items)
						this.examSearchWhere.page = res.data.page + 1
						this.isFinish = res.data.items.length > 0 ? false : true
						this.loadStatus = res.data.items.length > 0 ? "more" : "nomore"
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 获取顶部菜单导航
			getMenuList() {
				getHomeMenuList().then(res => {
					if (res.code == 100) {
						this.menuList = res.data
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 轮播图
			getBannerList() {
				getBannerList({
					position: "min_home"
				}).then(res => {
					if (res.code == 100) {
						this.swiperList = res.data
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 轮播图切换
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			// 点击公告跳转
			clickNotice(e) {
				console.log(e)
				let url = this.noticeListArray[e].navigate
				if (url == "") {
					this.$func.showToast("暂无跳转地址")
					return
				}
				this.tn(url)
			},
			// 跳转
			tn(e) {
				console.log(e)
				this.$func.navigatorTo(e)
			},
		},
		onReachBottom() {
			this.getRecommendExamList()
		}
	}
</script>

<style lang="scss" scoped>
	.template-index {
		max-height: 100vh;
	}

	.collection-remark {
		font-size: 24rpx;
	}

	.tn-tabbar-height {
		min-height: 100rpx;
		height: calc(120rpx + env(safe-area-inset-bottom) / 2);
	}

	/* 阴影*/
	.home-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 5rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			margin-left: 30rpx;
			flex-basis: 5%;
		}

		&__search {
			flex-basis: 60%;
			width: 100%;
			height: 100%;

			&__box {
				width: 100%;
				height: 70%;
				padding: 10rpx 0;
				margin: 0 30rpx;
				border-radius: 60rpx 60rpx 0 60rpx;
				font-size: 24rpx;
			}

			&__icon {
				padding-right: 10rpx;
				margin-left: 20rpx;
				font-size: 30rpx;
			}

			&__text {
				// color: #AAAAAA;
			}
		}
	}

	// .logo-image {
	// 	width: 65rpx;
	// 	height: 65rpx;
	// 	position: relative;
	// }

	// .logo-pic {
	// 	background-size: cover;
	// 	background-repeat: no-repeat;
	// 	background-attachment:fixed;
	// 	background-position: top;
	// 	border-radius: 50%;
	// }

	/* 自定义导航栏内容 end */


	/* 轮播视觉差 start */
	.card-swiper {
		height: 350rpx !important;
	}

	.card-swiper swiper-item {
		width: 750rpx !important;
		left: 0rpx;
		box-sizing: border-box;
		padding: 10rpx 20rpx 10rpx 20rpx;
		overflow: initial;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		transform: scale(1);
		transition: all 0.2s ease-in 0s;
		will-change: transform;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
		will-change: transform;
	}

	.card-swiper swiper-item .swiper-item-text {
		padding-top: 10%;
		text-align: center;
		width: 100%;
		display: block;
		height: 100%;
		border-radius: 10rpx;
		transform: translate(100rpx, 0rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
		will-change: transform;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item-text {
		margin-top: -300rpx;
		width: 100%;
		transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
		will-change: transform;
	}

	.image-banner {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
		height: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		z-index: 9999;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.spot {
		background-color: #FFFFFF;
		opacity: 0.4;
		width: 10rpx;
		height: 10rpx;
		border-radius: 20rpx;
		top: -60rpx;
		margin: 0 8rpx !important;
		position: relative;
	}

	.spot.active {
		opacity: 0.6;
		width: 30rpx;
		background-color: #FFFFFF;
	}

	/* 资讯主图 start*/
	.image-article {
		border-radius: 8rpx;
		width: 220rpx;
		height: 120rpx;
		position: relative;
	}

	.image-design {
		padding: 140rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	// 试题列表图片结束

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.blue-title::before {
		content: "";
		position: absolute;
		display: block;
		width: 80rpx;
		height: 26rpx;
		background: #269EFC;
		margin-top: 24rpx;
		margin-left: 75rpx;
		opacity: 0.3;
		z-index: -1;
		border-radius: 4rpx;
	}


	.icon12 {
		&__item {
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://img1.imgtp.com/2023/08/23/jsZ3eCk2.png);


				}
			}
		}
	}

	/* 热门图片 start*/
	.image-tuniao1 {
		padding: 164rpx 0rpx 162rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-tuniao2 {
		padding: 74rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-tuniao3 {
		padding: 90rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	/* 胶囊banner*/
	.image-capsule {
		padding: 100rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-piccapsule {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 20rpx 20rpx 0 0;
	}

	/* 工作区展示 start */
	.tn-info {

		&__container {
			// margin-top: 10rpx;
			// margin-bottom: 10rpx;
		}

		&__item {
			width: 47.7%;
			margin: 15rpx 0rpx 30rpx 0rpx;
			padding: 40rpx 30rpx;
			border-radius: 10rpx;


			position: relative;
			z-index: 1;

			&::after {
				content: " ";
				position: absolute;
				z-index: -1;
				width: 100%;
				height: 100%;
				left: 0;
				bottom: 0;
				border-radius: inherit;
				opacity: 1;
				transform: scale(1, 1);
				background-size: 100% 100%;
				background-image: url(https://img1.imgtp.com/2023/08/23/vmZXAACU.png);
			}

			&__left {

				&--icon {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					font-size: 40rpx;
					margin-right: 20rpx;
					position: relative;
					z-index: 1;

					&::after {
						content: " ";
						position: absolute;
						z-index: -1;
						width: 100%;
						height: 100%;
						left: 0;
						bottom: 0;
						border-radius: inherit;
						opacity: 1;
						transform: scale(1, 1);
						background-size: 100% 100%;
						background-image: url(https://img1.imgtp.com/2023/08/23/ziaWIK10.png);
					}
				}

				&__content {
					font-size: 25rpx;

					&--data {
						color: rgba(255, 255, 255, 0.5);
						margin-top: 5rpx;
						// font-weight: bold;
					}
				}
			}

			&__right {
				&--icon {
					position: absolute;
					right: 0rpx;
					top: 50rpx;
					font-size: 100rpx;
					width: 108rpx;
					height: 108rpx;
					text-align: center;
					line-height: 60rpx;
					opacity: 0.15;
				}
			}

			&__bottom {
				box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.12);
				border-radius: 0 0 10rpx 10rpx;
				position: absolute;
				width: 85%;
				line-height: 15rpx;
				left: 50%;
				bottom: -15rpx;
				transform: translateX(-50%);
				z-index: -1;
				text-align: center;
			}
		}
	}

	/* 工作区展示 end */
</style>